#### MODELS THAT USE IMPUTATION: (TABLE 4)
library(ergm)
library(stargazer)
library(methods)
#library(doMC)
#registerDoMC(28) #If applicable, use parallel processing
load("PSRM_replication_image_networks_IMP.RData")
control.min = control.ergm(MCMC.burnin=1000000, MCMC.interval=200, MCMC.samplesize=300000, MCMLE.maxit=100) 
#control.min = control.ergm(MCMC.burnin=10000, MCMC.interval=50, MCMC.samplesize=20000, MCMLE.maxit=30)

sink("PSRM_replication_logERGM_tables4.txt")
print("ALTERNATIVE SPECIFICATIONS WITH IMPUTATION: (TABLE 4)")

netcom <- delete.vertices(netcom, which(is.na(netcom %v% "ideology")))

set.seed(12)
fit1b <- ergm(netcom~edges+ absdiff("n.mandates") + absdiff("ideology") + nodematch("education", diff=F)+nodematch("floor", diff=F) + nodematch("leadership", diff=T) + nodematch("UF", diff=F) +nodematch("party", diff=F)+ transitiveties(), estimate="MLE", control=control.min)
netsoc <- delete.vertices(netsoc, which(is.na(netsoc %v% "ideology")))
set.seed(12)
fit2b <- ergm(netsoc~edges+ absdiff("n.mandates") + absdiff("ideology") + nodematch("education", diff=F)+nodematch("floor", diff=F) + nodematch("leadership", diff=T) + nodematch("UF", diff=F) +nodematch("party", diff=F)+ transitiveties(), estimate="MLE", control=control.min)
netinfo <- delete.vertices(netinfo, which(is.na(netinfo %v% "ideology")))
set.seed(12)
fit3b <- ergm(netinfo~edges+ absdiff("n.mandates") + absdiff("ideology") + nodematch("education", diff=F)+nodematch("floor", diff=F) + nodematch("leadership", diff=T) + nodematch("UF", diff=F) +nodematch("party", diff=F)+ transitiveties(), estimate="MLE", control=control.min)
stargazer(fit1b, fit2b, fit3b, title = "TABLE 4", out="results_table_4_only.txt")

sink()
